<template>
  <!--会签管理-我的提交列表-付款计划编辑弹窗-表单-->
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled" class="scroll-view" style="height: 600px">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <!-- <a-row>
          <a-col :span="24" style="margin-left: -50px;">
            <a-form-model-item label="标题" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="name">
              <a-input v-model="model.title" placeholder="请输入标题"></a-input>
            </a-form-model-item>
          </a-col>

          <a-col :span="24" style="margin-left: -50px;">
            <a-form-model-item label="项目" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="projectName">
              <a-select :options="levelOneOptions" placeholder="请选择项目" v-model="model.projectName">

              </a-select>
            </a-form-model-item>
          </a-col>
          <a-col :span="20" style="margin-left: 37px;">
            <a-form-model-item label="" :labelCol="labelCol" :wrapperCol="wrapperCol" style="width: 600px;"
              prop="otherName">

              <span style="display: inline-block;width: 80px;height: 50px;">(1)预计收款:</span> <a-input
                v-model="model.gatheringTotal" style="display: inline-block;width: 243px;"></a-input>
              <br />
              <span style="display: inline-block;width: 85px;height: 50px;margin-left: 13px;">劳务等款项：</span><a-input
                v-model="model.gatheringPaymentServices" style="display: inline-block;width: 225px;"></a-input>
              <br />
              <span style="display: inline-block;width: 70px;height: 50px;margin-left: 13px;">劳务工资：</span><a-input
                v-model="model.gatheringLaborWages" style="display: inline-block;width: 243px;"></a-input>



            </a-form-model-item>
          </a-col>
          <a-col :span="20" style="margin-left: 37px;">
            <a-form-model-item label="" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="bankAccount">
              <span style="display: inline-block;width: 190px;height: 50px;">(2)对下班组计划支付劳务费:</span> <a-input
                v-model="model.serviceFeeTotal" style="width: 140px;display:inline-block ;"></a-input>
              <br />
              <span style="display: inline-block;width: 100px;height: 50px;margin-left: 20px;">劳务等款项：</span><a-input
                v-model="model.serviceFeePayment" style="width: 210px;display:inline-block ;"></a-input>
              <br />
              <span style="display: inline-block;width: 80px;height: 50px;margin-left: 20px;"> 劳务工资：</span><a-input
                v-model="model.serviceFeeLaborWages" style="width: 230px;display:inline-block ;"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="20" style="margin-left: 37px;">
            <a-form-model-item label="" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="bank">
              <span style="display: inline-block;width: 160px;height: 50px;">(3)计划支付材料等款项:</span><a-input
                v-model="model.gatheringMaterialsTotal" style="width: 170px;display:inline-block ;"></a-input>
              <br />

              <span style="display: inline-block;width: 70px;height: 50px;margin-left: 20px;">材料费：</span><a-input
                v-model="model.gatheringMaterialsExpense" style="width: 240px;display:inline-block ;"></a-input>
              <br />
              <span style="display: inline-block;width: 70px;height: 50px;margin-left: 20px;"> 机械费：</span><a-input
                v-model="model.gatheringMaterialsMachine" style="width: 240px;display:inline-block ;"></a-input>
              <br />
              <span style="display: inline-block;width: 50px;height: 50px;margin-left: 20px;">其他：</span><a-input
                v-model="model.gatheringMaterialsOther" style="width: 260px;display:inline-block ;"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="20" style="margin-left: 37px;">
            <a-form-model-item label="" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="project">
              <span style="display: inline-block;width: 130px;height: 50px;">(4)项目部直签支出:</span> <a-input
                v-model="model.projectTotal" style="width: 200px;display:inline-block ;"></a-input>
              <br />
              <span style="display: inline-block;width: 60px;height: 50px;margin-left: 20px;">劳务费:</span> <a-input
                v-model="model.projectFeePayment" style="width: 250px;display:inline-block ;"></a-input>
              <br />
              <span style="display: inline-block;width: 60px;height: 50px;margin-left: 20px;">材料费：</span><a-input
                v-model="model.projectMaterialsExpense" style="width: 250px;display:inline-block ;"></a-input>
              <br />
              <span style="display: inline-block;width: 60px;height: 50px;margin-left: 20px;">机械费：</span><a-input
                v-model="model.projectMachineryCost" style="width: 250px;display:inline-block ;"></a-input>
              <br />
              <span style="display: inline-block;width: 60px;height: 50px;margin-left: 20px;">其他：</span><a-input
                v-model="model.projectOther" style="width: 250px;display:inline-block ;"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="20" style="margin-left: 37px;">
            <a-form-model-item label="" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="paymoney">
              <span style="display: inline-block;width: 160px;height: 50px;">(5)项目部预留备用资金:</span><a-input
                v-model="model.projectReservedMoney" style="width: 170px;display:inline-block ;"></a-input>
            </a-form-model-item>
          </a-col>

          <a-col :span="12">
            <a-form-model-item label="备注" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="fileList">
              <textarea v-model="model.remark" cols="80" rows="5"></textarea>
            </a-form-model-item>
          </a-col>
          <a-col :span="16">
            <a-form-model-item label="附件资料" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="fileList">
              <j-upload v-model="model.attachment"></j-upload>
            </a-form-model-item>
          </a-col>
        </a-row> -->
        <a-row>
          <a-col :span="12">
            <a-form-model-item label="标题" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="name">
              <a-input v-model="model.title" placeholder="请输入标题"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="项目" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="projectId">
              <!-- <a-select :options="levelOneOptions" placeholder="请选择项目" v-model="model.projectId">
              </a-select> -->
              <a-select :disabled="disabled"  placeholder="请选择项目" :value="model.projectName" @change="handleChange('project',$event)">
                <a-select-option v-for="(item,index) in levelOneOptions" :key="index" :value="item">
                      {{item.label}}
                    </a-select-option>
              </a-select>
            </a-form-model-item>
          </a-col>
        </a-row>
        
        <a-row>
          <a-col :span="24">
            <div style="margin-left: 30px;line-height: 40px;font-size: 16px;font-weight: 600;">预计收款：</div>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="总金额" :labelCol="labelCol3" :wrapperCol="wrapperCol3" prop="gatheringTotal"
              style="margin-bottom: 10px;margin-left: 20px;">
              <a-input v-model="model.gatheringTotal" style="width: 314px;"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="劳务等款项" :labelCol="labelCol" :wrapperCol="wrapperCol"
              prop="gatheringPaymentServices" style="margin-bottom: 10px;">
              <a-input v-model="model.gatheringPaymentServices"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="劳务工资" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="gatheringLaborWages"
              style="margin-bottom: 30px;">
              <a-input v-model="model.gatheringLaborWages"></a-input>
            </a-form-model-item>
          </a-col>
        </a-row>
        
        <a-row>
          <a-col :span="24">
            <div style="margin-left: 30px;line-height: 40px;font-size: 16px;font-weight: 600;">对下班组计划支付劳务费：</div>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="总金额" :labelCol="labelCol3" :wrapperCol="wrapperCol3" prop="serviceFeeTotal"
              style="margin-bottom: 10px;margin-left: 20px;">
              <a-input v-model="model.serviceFeeTotal" style="width: 314px;"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="劳务等款项" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="serviceFeePayment"
              style="margin-bottom: 10px;">
              <a-input v-model="model.serviceFeePayment"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="劳务工资" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="serviceFeeLaborWages"
              style="margin-bottom: 30px;">
              <a-input v-model="model.serviceFeeLaborWages"></a-input>
            </a-form-model-item>
          </a-col>
        </a-row>
        
        <a-row>
          <a-col :span="24">
            <div style="margin-left: 30px;line-height: 40px;font-size: 16px;font-weight: 600;">计划支付材料等款项：</div>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="总金额" :labelCol="labelCol3" :wrapperCol="wrapperCol3"
              prop="gatheringMaterialsTotal" style="margin-bottom: 10px;margin-left: 20px;">
              <a-input v-model="model.gatheringMaterialsTotal" style="width: 314px;"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="材料费" :labelCol="labelCol" :wrapperCol="wrapperCol"
              prop="gatheringMaterialsExpense" style="margin-bottom: 10px;">
              <a-input v-model="model.gatheringMaterialsExpense"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="机械费" :labelCol="labelCol" :wrapperCol="wrapperCol"
              prop="gatheringMaterialsMachine" style="margin-bottom: 10px;">
              <a-input v-model="model.gatheringMaterialsMachine"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="其他" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="gatheringMaterialsOther"
              style="margin-bottom: 30px;">
              <a-input v-model="model.gatheringMaterialsOther"></a-input>
            </a-form-model-item>
          </a-col>
        </a-row>
        
        <a-row>
          <a-col :span="24">
            <div style="margin-left: 30px;line-height: 40px;font-size: 16px;font-weight: 600;">项目部直签支出：</div>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="总金额" :labelCol="labelCol3" :wrapperCol="wrapperCol3" prop="projectTotal"
              style="margin-bottom: 10px;margin-left: 20px;">
              <a-input v-model="model.projectTotal"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="劳务费:" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="projectFeePayment"
              style="margin-bottom: 10px;">
              <a-input v-model="model.projectFeePayment"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="机械费" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="projectMachineryCost"
              style="margin-bottom: 10px;">
              <a-input v-model="model.projectMachineryCost"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="材料费" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="projectMaterialsExpense"
              style="margin-bottom: 10px;">
              <a-input v-model="model.projectMaterialsExpense"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="其他" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="projectOther"
              style="margin-bottom: 30px;">
              <a-input v-model="model.projectOther"></a-input>
            </a-form-model-item>
          </a-col>
        </a-row>
        
        <a-row>
          <a-col :span="5">
            <div style="margin-left: 30px;line-height: 40px;font-size: 16px;font-weight: 600;">项目部预留备用资金：</div>
          </a-col>
          <a-col :span="19">
            <a-form-model-item label="" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="projectReservedMoney"
              style="margin-bottom: 30px;">
              <a-input v-model="model.projectReservedMoney" style="width: 100%;"></a-input>
            </a-form-model-item>
          </a-col>
        </a-row>
        
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="备注" :labelCol="labelCol2" :wrapperCol="wrapperCol2" prop="remark"
              style="margin-bottom: 10px;margin-left: 20px;">
              <textarea v-model="model.remark" cols="100" rows="3" style="width: 93%;"></textarea>
            </a-form-model-item>
          </a-col>
        </a-row>
        
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="附件资料" :labelCol="labelCol2" :wrapperCol="wrapperCol2" prop="attachment"
              style="margin:0 60px 10px 20px;">
              <j-upload v-model="model.attachment"></j-upload>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
    <!-- <a-button @click="chexiao" type="primary" style="color: white; margin-left: 650px;">撤销</a-button> -->
    <!-- <a-button @click="submitForm1" type="primary" style="color: white; margin-left: 650px;">提交</a-button> -->
    <j-modal class="modal-privacy" :title="title" :visible="visible1" :disableScreenClick="true" okText="确定"
      cancelText="取消" @cancel="cancelPrivacy" @ok="confirmPrivacy">
      <textarea cols="70" rows="5" placeholder="请输入撤销原因"></textarea>

      <!-- <div style="font-size: 20px;width: 200px;height: 20px;margin: 0 auto;margin-top: 10px;">确定提交吗？</div> -->
    </j-modal>
  </a-spin>
</template>

<script>
  import {
    httpAction,
    getAction
  } from '@/api/manage'
  import {
    deleteByDepartId,
    queryUserOtherTreeList,
    searchByKeywords
  } from '@/api/api'
  import {
    validateDuplicateValue
  } from '@/utils/util'

  export default {
    name: 'WtBrandForm',
    components: {},
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false,
      },
    },
    data() {
      return {
        title: '撤销原因',
        model: {
          countersignId: '',
          projectName: '',
          projectId:'',
          attachment: '',
          status: "1"
        },
        visible1: false,
        labelCol: {
          xs: {
            span: 24
          },
          sm: {
            span: 5
          },
        },
        wrapperCol: {
          xs: {
            span: 24
          },
          sm: {
            span: 16
          },
        },
        labelCol2: {
          xs: {
            span: 24
          },
          sm: {
            span: 2
          },
        },
        wrapperCol2: {
          xs: {
            span: 24
          },
          sm: {
            span: 22
          },
        },
        labelCol3: {
          xs: {
            span: 24
          },
          sm: {
            span: 2
          },
        },
        wrapperCol3: {
          xs: {
            span: 24
          },
          sm: {
            span: 8
          },
        },
        confirmLoading: false,
        validatorRules: {},
        levelOneOptions: [],
        // levelTwoOptions: [],
        // levelThreeOptions: [],
        treeData: [],

        templateId: '',
        treeData1: [],
        // departTree: [],
        fileList: [],
        url: {
          add: '/wtBrand/add',
          edit: '/countersign/wtCountersignPaymentPlan/edit',
          anew: '/countersign/wtCountersignPaymentPlan/editSubmit',
          queryById: '/wtBrand/queryById',
        },
        pageType: 'edit', //edit-编辑 anew-重新提交
      }
    },
    computed: {
      formDisabled() {
        return this.disabled
      },
    },
    created() {
      //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model))


    },
    methods: {
      handleChange(type,item){
        console.log(1,type,item);
        if(type === 'project'){
          this.model.projectName = item.label;
          this.model.projectId = item.value;
        }
      },
      confirmPrivacy() {
        // console.log('同意了用户协议')
        // console.log(this.privacyDialogShow)l
        this.visible1 = false
        // console.log(this.privacyDialogShow)
      },
      cancelPrivacy() {
        // console.log('拒绝了用户协议')
        this.visible1 = false
      },
      loadTree(record) {
        var that = this
        getAction(`/countersign/wtCountersignPaymentPlan/queryByCountersignId?countersignId=${record.id}`).then((
        res) => {
          if (res.success) {
            that.treeData1 = res.result
            // var treeList1 = res.result
            this.model = that.treeData1
            // console.log('dwaq', this.treeData1)
            // for (let a = 0; a < treeList1.length; a++) {
            //   // console.log('ewq2');
            //   // let temp = treeList1[a]
            //   // temp.isLeaf = temp.leaf
            //   // that.treeData1.push(temp)
            // // console.log('dwaq1',that.treeData1);

            // }
            // that.model.id=that.treeData[0].id
            getAction(`/sys/sysDepart/getDepartByOrgType?orgType=1`).then((res) => {
              if (res.success) {
                this.treeData = []
                let treeList = res.result
                for (let a = 0; a < treeList.length; a++) {
                  let temp = treeList[a]
                  temp.isLeaf = temp.leaf
                  this.treeData.push(temp)
                }

                this.levelOneOptions = [...this.treeData].map((v) => {
                  return {
                    ...v,
                    value: v.id,
                    label: v.departName,
                  }
                })
                let info = that.levelOneOptions.filter((item) => {
                  // console.log('sew', item)
                  return item.departName === that.model.projectName
                })
                console.log('sew1', info);
                that.model.projectId = info.id
              }
            })
          }
        })

      },
      add() {
        this.edit(this.modelDefault)
      },
      edit(record, type) {
        // this.model = Object.assign({}, record)
        if (!!type) {
          this.pageType = type;
        }
        this.visible = true
        this.loadTree(record)
        // console.log('ew',record);
        this.templateId = record.id

      },
      chexiao() {
        this.visible1 = true
      },
      submitForm(record) {
        const that = this
        if (!this.model.attachment) {
          that.$message.warning('附件资料不能为空,请上传')
        } else {
          // 触发表单验证
          this.$refs.form.validate((valid) => {
            if (valid) {
              that.confirmLoading = true
              let httpurl = ''
              if (that.pageType === 'edit') {
                httpurl = that.url.edit
              } else if (that.pageType === 'anew') {
                httpurl = that.url.anew
              }
              that.model.countersignId = that.templateId
              that.model.status = record;
              that.model.list = that.model.list
              // console.log('wq',that.model);
              // debugger
              console.log('提交表单', that.model)
              httpAction(httpurl, this.model, 'POST')
                .then((res) => {
                  if (res.success) {
                    that.$message.success(res.message)
                    that.$emit('ok')
                  } else {
                    that.$message.warning(res.message)
                  }
                })
                .finally(() => {
                  that.confirmLoading = false
                })
            }
          })
        }
        
      },
    },
  }
</script>
<style scoped>
  .scroll-view {
    overflow: auto;
    overflow-y: scroll;
  }
</style>